#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int> ;

namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout


}

const int kN = 2e5 + 5, kLog = 20;
int n, q, tot;
int fa[kN], siz[kN], son[kN], top[kN], dfn[kN], rev[kN], bel[kN];
ll sum[kN];
vector<int> sub[kN], sdfn[kN];
vector<pii> g[kN];

int Mindfn(int x, int y) { return dfn[x] < dfn[y] ? x : y; }
struct ST {
  int mn[kLog][kN];
  void Build() {
    for(int i = 1; i < kLog; i++) {
      for(int l = 1; l + (1 << i) - 1 <= n; l++) {
        mn[i][l] = Mindfn(mn[i - 1][l], mn[i - 1][l + (1 << i - 1)]);
      }
    }
  }
  int LCA(int x, int y) {
    if(x == y) return x;
    x = dfn[x];
    y = dfn[y];
    if(x > y) swap(x, y);
    int p = __lg(y - x++);
    return Mindfn(mn[p][x], mn[p][y - (1 << p) + 1]);
  }
  ll Dist(int x, int y) { return sum[x] + sum[y] - 2 * sum[LCA(x, y)]; }
}st;
struct ST2 {
  int mn[kLog][kN];
  void Build() {
    for(int i = 1; i < n; i++) mn[0][i] = st.LCA(i, i + 1);
    for(int i = 1; i < kLog; i++) {
      for(int l = 1; l + (1 << i) <= n; l++) {
        mn[i][l] = Mindfn(mn[i - 1][l], mn[i - 1][l + (1 << i - 1)]);
      }
    }
  }
  int LCA(int l, int r) {
    if(l == r) return l;
    int p = __lg(r-- - l);
    return Mindfn(mn[p][l], mn[p][r - (1 << p) + 1]);
  }
}st2;

struct SGT {
  int len;
  vector<int> mx;
  void Build(vector<int> a) {
    a.insert(a.begin(), 0);
    int n = a.size();
    for(len = 1; len < n; len *= 2) ;
    mx.resize(2 * len, 0);
    for(int i = 0; i < n; i++) mx[i + len] = a[i];
    for(int i = len - 1; ~i; i--) {
      mx[i] = max(mx[2 * i], mx[2 * i + 1]);
    }
  }
  int Query(int l, int r) {
    int ans = 0;
    l += len, r += len + 2;
    while(l + 1 != r) {
      if(!(l & 1)) ans = max(ans, mx[++l]);
      if(r & 1) ans = max(ans, mx[--r]);
      l /= 2, r /= 2;
    }
    return ans;
  }
};
SGT sgt[kN];

bool In(int anc, int x) {
  return (dfn[x] >= dfn[anc]) && (dfn[x] < dfn[anc] + siz[anc]);
}
void DFS(int x, int fa) {
  ::fa[x] = fa;
  siz[x] = 1;
  for(pii k : g[x]) {
    int to = k.first, w = k.second;
    if(to == fa) continue;
    sum[to] = sum[x] + w;
    DFS(to, x);
    siz[x] += siz[to];
    if(siz[son[x]] < siz[to]) son[x] = to;
  }
}
void Push(int x, int fa, int b, vector<int> &v) {
  bel[x] = b;
  v.push_back(x);
  for(pii k : g[x]) {
    int to = k.first;
    if(to != fa) Push(to, x, b, v);
  }
}
void DFS2(int x, int fa, int tp) {
  top[x] = tp;
  dfn[x] = ++tot;
  rev[tot] = x;
  st.mn[0][tot] = fa;
  if(son[x]) DFS2(son[x], x, tp);
  for(pii k : g[x]) {
    int to = k.first;
    if((to != fa) && (to != son[x])) DFS2(to, x, to);
  }
  if(tp != x) return ;
  for(int i = x; i; i = son[i]) {
    bel[i] = i;
    sub[x].push_back(i);
    for(pii k : g[i]) {
      int to = k.first;
      if((to != ::fa[i]) && (to != son[i])) Push(to, i, i, sub[x]);
    }
  }
  sort(sub[x].begin(), sub[x].end());
  sdfn[x].resize(sub[x].size());
  for(int i = 0; i < sub[x].size(); i++) sdfn[x][i] = dfn[bel[sub[x][i]]];
  sgt[x].Build(sdfn[x]);
}
int Query(int p, int l, int r) {
  for(int i = p; i; i = fa[top[i]]) {
    int tp = top[i];
    auto itl = lower_bound(sub[tp].begin(), sub[tp].end(), l);
    if((itl == sub[tp].end()) || (*itl > r)) continue;
    auto itr = upper_bound(sub[tp].begin(), sub[tp].end(), r) - 1;
    int pl = itl - sub[tp].begin();
    int pr = itr - sub[tp].begin();
    return rev[sgt[tp].Query(pl, pr)];
  }
  assert(0);
}

int main() {
  freopen("memory.in", "r", stdin);
  freopen("memory.out", "w", stdout);
  // ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  for(int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  DFS(1, 0);
  DFS2(1, 0, 1);
  st.Build();
  st2.Build();
  ll lst = 0;
  for(int i = 1; i <= q; i++) {
    ll p, l, r;
    cin >> p >> l >> r;
    p ^= lst, l ^= lst, r ^= lst;
    int lca = st2.LCA(l, r);
    if(In(p, lca)) cout << (lst = sum[lca] - sum[p]) << "\n";
    else {
      int get = Query(p, l, r);
      if(In(p, get)) cout << (lst = 0) << "\n";
      else {
        get = st.LCA(get, p);
        if(In(get, lca)) cout << (lst = st.Dist(p, lca)) << "\n";
        else cout << (lst = sum[p] - sum[get]) << "\n";
      }
    }
  }
  return 0;
}